//
//  ZTData.h
//  YSSmartHome
//
//  Created by Yahaong on 16/8/11.
//  Copyright © 2016年 yahaong. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "ZTJoinDevRecord.h"
#import "YHMarcros.h"
#import "XAISDK/XAI.h"

@class DataManager,ZTLinkage, ZTDevice, XAIGateway, Friend;

typedef NS_ENUM(NSInteger, GatewayCallbackType) {
    GatewayCallbackTypeName,
    GatewayCallbackTypePower,
    GatewayCallbackTypeConnectStatus,
    GatewayCallbackTypeLinkage,
};

typedef NS_ENUM(NSInteger, DeviceCallbackType) {
    DeviceCallbackTypeName,
    DeviceCallbackTypePower,
    DeviceCallbackTypeConnectStatus,
    DeviceCallbackTypeStatus,
};

typedef NS_ENUM(NSInteger, FriendCallbackType)
{
    FriendCallbackTypeName,
    FriendCallbackTypePower,
    FriendCallbackTypeConnectStatus,
    FriendCallbackTypeStatus,
};
#define kDataManager [DataManager sharedManager]
@protocol DataManagerRefreshDelegate <NSObject>
@optional
- (void)gatewayRefresh:(DataManager*__nonnull)manager callbackType:(GatewayCallbackType)callbackType;
- (void)deviceRefresh:(DataManager*__nonnull)manager callbackType:(DeviceCallbackType)callbackType;
- (void)friendRefresh:(DataManager*__nonnull)manager callbackType:(FriendCallbackType)callbackType;

- (void)dataRefresh:(DataManager* __nonnull)manager;
- (void)linkageRefresh:(DataManager*__nonnull)manager;
- (void)gatewayRefresh:(DataManager*__nonnull)manager;
- (void)newJoinRefresh:(DataManager* __nonnull)manager;
- (void)deviceHistoryOperationRefresh:(DataManager*__nonnull)manager apsn:(XAITYPEAPSN)apsn luid:(XAITYPELUID)luid;
- (void)imMessageRefresh:(DataManager* __nonnull)manager;
@end

@interface DataManager : NSObject
{
@public
    __block NSData  *m_picDataArray[DEV_CHANNEL_MAX*DEV_NUM_MAX];

}

NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, strong, readonly) NSMutableArray* cameraList;
@property (nonatomic, strong, readonly) NSMutableArray* gatewayListenList;
@property (nonatomic, strong, readonly) NSMutableArray* deviceListenList;
@property (nonatomic, strong, readonly) NSMutableArray* friendListenList;
@property (nonatomic, strong, readonly) NSMutableArray* linkageListenList;
@property (nonatomic, strong, readonly) NSMutableArray* bindGateModels;
@property (nonatomic, strong, readonly) NSMutableArray <NSNumber *> * joinDevListenList;
@property (nonatomic, strong, readonly) NSMutableArray* deviceRefreshDelegates;
@property (nonatomic, strong, readonly) NSMutableArray* gatewayRefreshDelegates;
@property (nonatomic, strong, readonly) NSMutableArray* friendRefreshDelegates;
@property (nonatomic, strong, readonly) NSMutableArray* linkageRefreshDelegates;
@property (nonatomic, strong, readonly) NSMutableArray* imMessageRefreshDelegates;
@property (nonatomic, strong, readonly) NSMutableArray* deviceHistoryRefreshDelegates;
@property (nonatomic, strong, readonly) NSMutableArray* newJoinDelegates;
@property (nonatomic, strong, readonly) NSMutableArray* operationList;

+ (instancetype)sharedManager;

// 添加代理
- (void)addRefreshDelegate:(id<DataManagerRefreshDelegate>)delegate;
- (void)addGatewayRefreshDelegate:(id<DataManagerRefreshDelegate>)delegate;
- (void)addLinkageRefreshDelegate:(id<DataManagerRefreshDelegate>)delegate;
- (void)addNewJoinRefreshDelegate:(id<DataManagerRefreshDelegate>)delegate;
- (void)addFriendRefreshDelegate:(id<DataManagerRefreshDelegate>)delegate;
- (void)addHistoryOperationRefreshDelegate:(id<DataManagerRefreshDelegate>)delegate;
- (void)addIMMessageRefreshDelegate:(id<DataManagerRefreshDelegate>)delegate;

// 删除代理
- (void)removeRefreshDelegate:(id<DataManagerRefreshDelegate>)delegate;
- (void)removeGatewayRefreshDelegate:(id<DataManagerRefreshDelegate>)delegate;
- (void)removeLinkageRefreshDelegate:(id<DataManagerRefreshDelegate>)delegate;
- (void)removeNewJoinRefreshDelegate:(id<DataManagerRefreshDelegate>)delegate;
- (void)removeFriendRefreshDelegate:(id<DataManagerRefreshDelegate>)delegate;
- (void)removeHistoryOperationRefreshDelegate:(id<DataManagerRefreshDelegate>)delegate;
- (void)removeIMMessageRefreshDelegate:(id<DataManagerRefreshDelegate>)delegate;

// 增
- (void)addGateway:(XAIGateway *)gateway;
- (void)addDevice:(ZTDevice*)device;
- (void)addFriend:(Friend*)device;
- (void)addLinkage:(ZTLinkage*)aLink;

// 删
- (void)removeDeviceWithApsn:(XAITYPEAPSN)apsn luid: (XAITYPELUID)luid;
- (void)removeDeviceWithApsn:(XAITYPEAPSN)apsn;
- (BOOL)removeLinkageWithApsn: (XAITYPEAPSN) gatewayApsn linkID:(uint8_t)linkID;
- (void)removeLinkageWithApsn:(XAITYPEAPSN)gatewayApsn;
- (void)removeGatewayWithApsn:(XAITYPEAPSN)gatewayApsn;
- (void)removeFriendWithApsn:(XAITYPEAPSN)apsn luid: (XAITYPELUID)luid;
- (void)removeFriendWithApsn:(XAITYPEAPSN)apsn mobile: (NSString*)mobile;

// 查
- (ZTDevice * __nullable)fetchDeviceWithApsn:(XAITYPEAPSN)apsn luid: (XAITYPELUID)luid;
- (XAIGateway * __nullable)fetchGatewayWithApsn:(XAITYPEAPSN)apsn luid: (XAITYPELUID)luid;
- (Friend * __nullable)fetchFriendWithApsn:(XAITYPEAPSN)apsn luid: (XAITYPELUID)luid;
- (NSString *__nullable)allDeviceName;
+ (NSMutableArray* __nullable)roomNameLists;

//回调
- (void)callBack;
- (void)gatewayCallBack;
- (void)linkageCallBack;
- (void)imMessageCallBack;
- (void)newJoinDevCallBack;
- (void)deviceRefreshCallBackWithType:(DeviceCallbackType)callbackType;
- (void)friendRefreshCallBackWithType:(FriendCallbackType)callbackType;
- (void)gatewayCallBackWithType:(GatewayCallbackType)type;
- (void)deviceHistoryOperationCallBack:(XAITYPEAPSN)apsn luid:(XAITYPELUID)luid;

// 其他
- (BOOL)deleteJoinDev:(NSNumber*)luid;
- (void)setUnJoinDevList:(NSNumber*)luid;

//加锁
- (void)devlistLock;
- (void)gatewaylistLock;
- (void)linkagelistLock;
- (void)friendlistLock;
- (void)roomlistLock;
- (void)historyOperationLock;

//减锁
- (void)devlistUnlock;
- (void)gatewaylistUnlock;
- (void)linkagelistUnlock;
- (void)friendlistUnlock;
- (void)roomlistUnlock;
- (void)historyOperationUnlock;

NS_ASSUME_NONNULL_END
@end
